import pandas as pd
import os

# 检查文件是否存在
file_path = "/Users/jiandian/Downloads/wafer_1742362806894.xlsx"
if not os.path.exists(file_path):
    raise FileNotFoundError(f"文件不存在: {file_path}")

def normalization(cs):
    cs=(cs-cs.min())/(cs.max()-cs.min())
    return cs
def standardization(cs):
    cs=(cs-cs.mean())/cs.std()
    return cs
try:
    # 尝试读取（确保有权限）
    df = pd.read_excel(file_path, engine="openpyxl")
    print(df.head(),df.dtypes)  # 打印前5行确认数据
    print(df.describe())
    # 你的后续处理逻辑
    features = df.iloc[:, :-1].values
    print("======",type(features))
    cols = [f"x{i+1}" for i in range(features.shape[1])]
    df2 = pd.DataFrame(features, columns=cols)
    print(df2)
    print("---",df[df['QUANTITY']>1000])
    print(df.groupby(["INSPECTED BY"])["QUANTITY"])
    df2=df.loc[:,["QUANTITY","Material Type"]]
    # loc
    print("--",df2)

    #
    df.dropna(how='all')
    df.dropna(axis=1,how='all')
    df.dropna(axis=1,thresh=5)
    # 填充值，一般用均值，中值
    df.fillna(0)
    # applymap(f) 针对每个值做什么操作
    # apply(fn) 针对每一行做什么操作
    # 去量纲化，归一化
    df3=df2.apply(normalization)
    # 标准化
    df4=df2.apply(standardization)
    print(df3)
except PermissionError:
    print("权限不足，请检查文件权限或使用副本！")
except Exception as e:
    print(f"其他错误: {e}")

# pickle 序列化

